package com.bankwel.j3d;

import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

import com.bankwel.j3d.core.J3dMatrix;
import com.bankwel.j3d.core.J3dChannel;
import com.bankwel.j3d.model.Cube;
import com.bankwel.j3d.model.Object3d;
import com.bankwel.j3d.ui.J3dFrame;
import com.bankwel.j3d.ui.J3dProxy;
import com.bankwel.j3d.ui.J3dPanel;

/**
 * 
 * @author Acce1erator
 *
 */
public class App {

	public static void main(String[] args) {

		float pi = (float) Math.PI;

		JFrame frame = new J3dFrame();
		int width = frame.getContentPane().getWidth();
		int height = frame.getContentPane().getHeight();
		J3dMatrix init = J3dChannel.unit();
		init.join(J3dChannel.rotateX(-pi / 6));
		init.join(J3dChannel.rotateY(-pi / 4));
		init.join(J3dChannel.rotateZ(pi / 3));
		init.join(J3dChannel.translate(width / 2f, height / 2f, 0f));

		Object3d obj = new Cube(init, 200);
		JPanel panel = new J3dPanel(obj, width, height);

		J3dMatrix action = J3dChannel.translate(-width / 2f, -height / 2f, 0f);
		action.join(J3dChannel.rotateX(pi / 360));
		action.join(J3dChannel.rotateY(pi / 360));
		action.join(J3dChannel.rotateZ(pi / 360));
		action.join(J3dChannel.translate(width / 2f, height / 2f, 0f));
		ActionListener proxy = new J3dProxy(obj, panel, action);

		frame.getContentPane().add(panel);
		panel.updateUI();
		new Timer(40, proxy).start();
	}
}
